<?php
class UsersController extends AppController {
	var $name = 'Users';
	var $helpers = array('Html');
	var $components = array('Init', 'Param');

	function beforeFilter() {
		if (!$this->Session->read('admin')) {
			$this->redirect('/login');
		}
		else {
			$this->Init->startup($this);
			$this->Admin = $this->Init->init();

			$this->set('dashboard',0);
			$this->set('content',0);
			$this->set('products',0);
			$this->set('component',0);
			$this->set('system',1);

			$this->set('title','Users Management');
			$this->set('sub_title', $this->Param->getAction($this->params));
  		}
	}

	function index(){
		$users = $this->User->find('all', array(
									'conditions' => array(
										'User.status' => 1
										),
									'order' 	 => 'User.date desc'
									));
		$this->set('users',$users);
	}

	function edit($id = null){
		$this->helpers[] = 'Ck';
		$id = $this->Param->getID($this->params);

		if (isset($this->data)) {

			if ($this->User->save($this->data)) {
				$this->Session->setFlash('Done successfully!');
				$this->redirect('/users');
			}

		}
		else {
			if (isset($id) && ($id > 0)) {
				$this->data = $this->User->find('first',array(
					'conditions' => array('User.id' => $id)
				));

			}
		}
	}


	function del($id = null) {
		$id = $this->Param->getID($this->params);
		 $this->User->id = $id;
		 $this->User->delete();
		 $this->Session->setFlash('aaa');
		 $this->redirect('/menus');
	}

}
?>